<template>
	<view class="body">
		<!-- tab切换 -->
		<swiper-tab-head :tabBars="tabBars" :tabindex="tabindex" @tabtap="tabtap" scrollstyle="border-bottom:0;" scrollitem="width:33.3%;">

		</swiper-tab-head>

		<view class="uni-tab-bar">
			<swiper class="swiper-box" :style="{height:swiperheight+'px'}" :current="tabindex" @change="tabChange">
				<swiper-item v-for="(items,index) in newlist" :key="index">
					<!-- @scrolltolower这个是触底事件 -->
					<scroll-view scroll-y class="list" @scrolltolower="loadmores(index)">
						<template v-if="items.list.length>0">
							<!-- 图文列表 -->
							<!-- 好友列表 -->
							<block v-for="(item,index1) in items.list" :key="index1">
								<user-list :item="item" :index="index1"></user-list>
							</block>
							<!-- 上拉刷新 -->
							<loadMore :loadtext="items.loadtext"></loadMore>
						</template>
						<template v-else>
							<!-- 无内容 默认的地方-->
							<noThing></noThing>
						</template>
					</scroll-view>
				</swiper-item>

			</swiper>
		</view>

	</view>
</template>

<script>
	import swiperTabHead from "../../components/index/swiper-tab.vue";
	import userList from "../../components/user-list/user-list.vue";
	import loadMore from "../../components/common/load-more.vue";
	import noThing from "../../components/common/nothing.vue";
	export default {
		components: {

			swiperTabHead,
			loadMore,
			userList,
			noThing
		},
		data() {
			return {
				swiperheight: 500,
				tabindex: 0,
				tabBars: [{
						name: '关注',
						id: 'guanzhu',
						num: 10
					},
					{
						name: '人气',
						id: 'renqi',
						num: 30
					},
					{
						name: '推荐',
						id: 'tuijie',
						num: 66
					}
				],
				newlist: [{
						loadtext: "上拉加载更多",
						list: [{
								userpic: "../../static/srcc/touxiang.jpg",
								username: "Vincent",
								age: 21,
								sex: 0,
								isguanzhu: false
							},
							{
								userpic: "../../static/srcc/touxiang.jpg",
								username: "Vincent",
								age: 21,
								sex: 1,
								isguanzhu: true
							},
							{
									userpic: "../../static/srcc/touxiang.jpg",
									username: "Vincent",
									age: 21,
									sex: 0,
									isguanzhu: false
								},
								{
										userpic: "../../static/srcc/touxiang.jpg",
										username: "Vincent",
										age: 21,
										sex: 0,
										isguanzhu: false
									},
									{
											userpic: "../../static/srcc/touxiang.jpg",
											username: "Vincent",
											age: 21,
											sex: 0,
											isguanzhu: false
										},
										{
												userpic: "../../static/srcc/touxiang.jpg",
												username: "Vincent",
												age: 21,
												sex: 0,
												isguanzhu: false
											},
											{
													userpic: "../../static/srcc/touxiang.jpg",
													username: "Vincent",
													age: 21,
													sex: 0,
													isguanzhu: false
												},
												{
														userpic: "../../static/srcc/touxiang.jpg",
														username: "Vincent",
														age: 21,
														sex: 0,
														isguanzhu: false
													}
						]

					},
					{
						loadtext: "上拉加载更多",
						list: [{
								userpic: "../../static/srcc/touxiang.jpg",
								username: "天空",
								age: 21,
								sex: 1,
								isguanzhu: false
							},
							{
								userpic: "../../static/srcc/touxiang.jpg",
								username: "天空",
								age: 25,
								sex:0,
								isguanzhu: false
							}
						]

					},
					{
						loadtext: "上拉加载更多",
						list: [{
								userpic: "../../static/srcc/touxiang.jpg",
								username: "昵称",
								age: 21,
								sex: 0,
								isguanzhu: false
							},
							{
								userpic: "../../static/srcc/touxiang.jpg",
								username: "昵称",
								age: 21,
								sex: 1,
								isguanzhu: true
							}
						]

					}
				]
			}
		},
		//监听导航按钮事件

		onNavigationBarButtonTap(e) {
			if (e.index == 0) {
				uni.navigateBack({
					delta: 1
				})
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					let height = res.windowHeight - uni.upx2px(100);
					console.log(res.screenHeight);
					console.log(height);
					this.swiperheight = height;
				}
			});
		},
		methods: {
			// 点击事件
			tabtap(index) {
				console.log(index);
				this.tabindex = index;
			},
			//滑动事件
			tabChange(e) {
				console.log(JSON.stringify(e.detail))
				this.tabindex = e.detail.current;
			},
			loadmores(index) {
				//如果目前全等于加载更多我们就给他这个事件，不然就return
				if (this.newlist[index].loadtext != "上拉加载更多") {
					return;
				}
				//修改状态
				this.newlist[index].loadtext = "加载中...";
				//获取数据
				setTimeout(() => {
					//获取完成
					let obj = {
						userpic: "../../static/srcc/touxiang.jpg",
						username: "昵称",
						age: 21,
						sex: 1,
						isguanzhu: true
					};
					this.newlist[index].list.push(obj);
					this.newlist[index].loadtext = "上拉加载更多"
				}, 1000);


				//this.newlist[index].loadtext="没有更多数据了";
			}
		}
	}
</script>

<style>
	.body {
		padding: 0 20upx;
	}
</style>
